/**
 * Created by zhang_renyang on 15/1/3.
 */
var express = require('express');
var path = require('path');
var router = express.Router();
var Category = require('../model/category');
var Article = require('../model/article');

router.get('/',function(req,res){
    Category.tree(function(err,categories) {
        Article.pageQuery({is_recommend: true}, {pageNum: 1, pageSize: 3}, function (err, count, articles) {
            if (err) {
                next(err);
            } else {
                res.render('index', {
                    user: req.session.user,
                    articles: articles,
                    categories: categories,
                    success: req.flash('success').toString(),
                    error: req.flash('error').toString()
                });
            }
        });
    });
});

module.exports=router;